package slap.mvc;

import slap.annotation.Accept;
import slap.http.Request;
import slap.mvc.result.RenderStatic;

public final class DefaultHttpRequestController extends HttpRequestController{
	
	private static final String DEDICATED_APP_RESOURCE_PREFIX = "/static";
	private static final int DEDICATED_APP_RESOURCE_PREFIX_LENGTH = DEDICATED_APP_RESOURCE_PREFIX
			.length();
	
	private static final String SHARE = "/SHARE";
	private static final String SHARE_RESOURCE_PREFIX = "/share";
	private static final int SHARE_RESOURCE_PREFIX_LENGTH = SHARE_RESOURCE_PREFIX
			.length();
	
	public static final String FAVICON = "/favicon.ico";
	public static final String FAVICON_PATH = "/favicon.ico";
	
	@Accept(wildcard = DEDICATED_APP_RESOURCE_PREFIX + "/**")
	public void dedicated_resource() {
		String relative = Request.current().path()
				.substring(DEDICATED_APP_RESOURCE_PREFIX_LENGTH);
		this.renderStatic(relative);
	}

	@Accept(wildcard = SHARE_RESOURCE_PREFIX + "/**")
	public void shared_resource() {
		String relative = Request.current().path()
				.substring(SHARE_RESOURCE_PREFIX_LENGTH);
		throw new RenderStatic(SHARE + relative, application);
	}
	
	@Accept(FAVICON)
	public void favicon(){
		this.renderStatic(FAVICON_PATH);
	}
}